import { CellRenderer } from "../../../../../fl/controls/listClasses/CellRenderer";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { DataEvent } from "../../../events/DataEvent";
import { EffectManager } from "../../../manager/EffectManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { SmeltPlanData } from "../data/SmeltPlanData";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../../resource/ColorConfig";
import { GLabel } from "../../../../../com/mui/controls/GLabel";
import { LineBox } from "../../guide/LineBox";
//class SmeltPlanListCellRenderer
    
    export  class SmeltPlanListCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.mouseEnabled = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            var loc1=ResouceConst.getScaleBitmap("Friend_over");
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", loc1);
            this.setStyle("overSkin", loc1);
            this.setStyle("selectedDownSkin", loc1);
            this.setStyle("selectedOverSkin", loc1);
            this.setStyle("selectedUpSkin", loc1);
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=null;
            loc1 = GlobalClass.getBitmap(ImagesConst.PackItemBg);
            loc1.x = 5;
            loc1.y = 5;
            this.addChild(loc1);
            this._itemImg = new BaseItem();
            this._itemImg.setSize(32, 32);
            this._itemImg.isDragAble = false;
            this._itemImg.isDropAble = false;
            this._itemImg.isThrowAble = false;
            this._itemImg.isShowLock = false;
            this._itemImg.x = loc1.x + 3;
            this._itemImg.y = loc1.y + 3;
            this.addChild(this._itemImg);
            this._nameLabel = ObjCreate.createLabel("", 47, 7, 120, 40, flash.text.TextFormatAlign.LEFT, this, false, GlobalStyle.color1Uint);
            this._nameLabel.wordWrap = true;
            this._nameLabel.drawNow();
            return;
        }

        /* internal  */removeGuideEffect(arg1: DataEvent): void
        {
            if (this._lineBox && this.contains(this._lineBox)) 
            {
                if (this.contains(this._lineBox)) 
                {
                    this.removeChild(this._lineBox);
                }
                EffectManager.disposeLineBox(this._lineBox);
                Dispatcher.removeEventListener(EventName.SmeltRemoveGuideEffect, this.removeGuideEffect);
            }
            return;
        }

        public addGuide(): void
        {
            this._lineBox = EffectManager.getLineBox(this.width, this.height);
            this.addChildAt(this._lineBox, (this.numChildren - 1));
            Dispatcher.addEventListener(EventName.SmeltRemoveGuideEffect, this.removeGuideEffect);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            var loc1=arg1 as SmeltPlanData;
            if (loc1) 
            {
                this._itemImg.itemData = loc1.mainProduce;
                this._nameLabel.htmlText = HTMLUtil.addColor(loc1.mainProduce.itemInfo.item.name + (loc1.canSmeltNum > 0 ? " （" + loc1.canSmeltNum + "）" : ""), ColorConfig.instance.getItemColor(loc1.mainProduce.itemInfo.item.color).color);
            }
            else 
            {
                this._itemImg.itemData = null;
                this._nameLabel.htmlText = "";
            }
            return;
        }

        /* internal */ /* var */_itemImg: BaseItem;

        /* internal */ /* var */_nameLabel: GLabel;

        /* internal */ /* var */_lineBox: LineBox;
    }
